package org.jeecg.modules.front.util;

import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/** Native 支付下单为例 */
@Slf4j
@Configuration
public class WechatConfigUtil {

    /** 商户号 */
    @Value(value="${wx-public.merchantId}")
    private String merchantId;
    /** 商户API私钥路径 */
    @Value(value="${wx-public.privateKeyPath}")
    private String privateKeyPath;
    /** 商户证书序列号 */
    @Value(value="${wx-public.merchantSerialNumber}")
    private String merchantSerialNumber;
    /** 商户APIV3密钥 */
    @Value(value="${wx-public.apiV3key}")
    private String apiV3key;
    /** APPID */
    @Value(value="${wx-public.appId}")
    private String appId;
    /** 回调域名 */
    @Value(value="${wx-public.notifyUrl}")
    private String notifyUrl;

    private Config config;


    @PostConstruct
    public void init(){
        WechatUtil.setConfig(new RSAAutoCertificateConfig.Builder()
                .merchantId(merchantId)
                .privateKeyFromPath(privateKeyPath)
                .merchantSerialNumber(merchantSerialNumber)
                .apiV3Key(apiV3key)
                .build());
        WechatUtil.setMerchantId(merchantId);
        WechatUtil.setPrivateKeyPath(privateKeyPath);
        WechatUtil.setMerchantSerialNumber(merchantSerialNumber);
        WechatUtil.setApiV3key(apiV3key);
        WechatUtil.setAppId(appId);
        WechatUtil.setNotifyUrl(notifyUrl);
    }
}
